<?php
class ConexaoBanco {
	private $host = "localhost";
	private $usuario = "root";
	private $senha = "";
	private $nomeBanco = "portaldpcivil";
	private $con = false;

	public function conectar() {
		if(!$this->con){
		$mycon = mysql_connect($this->host,$this->usuario,$this->senha) or trigger_error(mysql_error());
		mysql_set_charset('UTF8', $mycon);
		
			if($mycon){
				
				$status = mysql_select_db($this->nomeBanco, $mycon) or trigger_error(mysql_error());
				if ($status) {
					$this->con = true;
					return true;
				}	
				else{
					return false;
				}
			}
			else {
				return false;
			}
		}
		else{
			return true;
		}
		
	}
	
	public function desconectar(){
		if($this->con){
			if (@mysql_close()) {
				$this->con = false;
				return true;
			}
			else {
				return false;
			}
		}
	}
	
	public function executarSql($sql){

		if(isset($sql)){
			mysql_query($sql) or die(mysql_error());
			return true;
		}
		else
			return false;		
	}
	
	public function executarConsulta($sql){
		if(isset($sql)){
			$res = mysql_query($sql);
			
			return $res;
		}
		else
			return false;
	}	
}

?>